package com.yy.young.travel.web;

import com.yy.young.common.util.CommonUtil;
import com.yy.young.common.util.Result;
import com.yy.young.common.util.StringUtils;
import com.yy.young.dal.util.Page;
import com.yy.young.interfaces.log.annotation.Log;
import com.yy.young.travel.model.SourceGrade;
import com.yy.young.travel.service.ISourceGradeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 资源评分管理服务
 * Created by hua on 2018-03-22.
 */
@Controller
@RequestMapping("/travel/sourceGrade")
public class SourceGradeController {

    @Resource(name="sourceGradeService")
    ISourceGradeService service;

    /**
     * 获取数据列表
     * @param sourceGrade
     * @param request
     * @return
     * @throws Exception
     */
    @Log("查询资源评分管理列表")
    @RequestMapping("/getSourceGradeList")
    @ResponseBody
    public Object getSourceGradeList(SourceGrade sourceGrade, HttpServletRequest request) throws Exception{
        List<SourceGrade> list = service.getSourceGradeList(sourceGrade);
        return new Result(list);
    }

    /**
     * 获取分页数据
     * @param sourceGrade
     * @param request
     * @return
     * @throws Exception
     */
    @Log("分页查询资源评分管理列表")
    @RequestMapping("/getSourceGradePage")
    @ResponseBody
    public Object getSourceGradePage(SourceGrade sourceGrade, HttpServletRequest request) throws Exception{
        Page page = CommonUtil.getPageFromRequest(request);
        List<SourceGrade> list = service.getSourceGradePage(sourceGrade, page);
        page.setData(list);
        return page;
    }

    /**
     * 获取单条数据
     * @param id
     * @param request
     * @return
     * @throws Exception
     */
    @Log("查询资源评分管理")
    @RequestMapping("/getSourceGrade")
    @ResponseBody
    public Object getSourceGrade(String id, HttpServletRequest request) throws Exception{
        SourceGrade sourceGrade = service.getSourceGrade(id);
        return new Result(sourceGrade);
    }

    /**
     * 新增
     * @param sourceGrade
     * @param request
     * @return
     * @throws Exception
     */
    @Log("新增资源评分管理")
    @RequestMapping("/insert")
    @ResponseBody
    public Object insert(SourceGrade sourceGrade, HttpServletRequest request) throws Exception{
        int num = service.insertSourceGrade(sourceGrade);
        return new Result();
    }

    /**
     * 修改
     * @param sourceGrade
     * @param request
     * @return
     * @throws Exception
     */
    @Log("修改资源评分管理")
    @RequestMapping("/update")
    @ResponseBody
    public Object update(SourceGrade sourceGrade, HttpServletRequest request) throws Exception{
        int num = service.updateSourceGrade(sourceGrade);
        return new Result();
    }

    /**
     * 删除
     * @param ids
     * @param id
     * @param request
     * @return
     * @throws Exception
     */
    @Log("删除资源评分管理")
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String ids, String id, HttpServletRequest request) throws Exception{
        Result result = new Result();
        if(StringUtils.isNotBlank(ids)) {
            String[] idArr = ids.split(",");
            int num = service.deleteSourceGrade(idArr);
        }else if(StringUtils.isNotBlank(id)){
            int num = service.deleteSourceGrade(id);
        }else{
            result.setCode(-1);
            result.setInfo("删除失败:待删除编号无效!");
        }
        return result;
    }

}